|
![](/i/fill.gif) |
Hi Warp,
Warp wrote:
> And why rand(seed(I1*I2)) doesn't give the desired result? It looks to me
> like it gives values between 0 and 1 quite randomly, not very related to
> I1 and I2.
Unfortunately, it doesn't work.
There are a couple of drastic problems in fact:
1) this function is symetric about the diagonals so, for example, the
points (2,3), (3,2), (-2,-3), (-3,-2) all give the same values. The axes
give 0*I2 or I1*0 and so return the same value along their length.
2) seed() itself is based on, I believe, a simple linear congruent
random generator. The first call to these tend to depend highly on the
seed value, being highly correlated for certain sequences.
I ran a test which showed this using
// --** start **--
#declare S = 30;
#declare X = -S; #while (X <= S)
#declare Y = -S; #while (Y <= S)
#declare Col = rand(seed(X*Y+3000));
box { <X,Y,0>-0.5, <X,Y,0>+0.5
pigment { colour rgb Col }
finish { ambient 1 diffuse 0 }
}
#declare Y = Y + 1; #end
#declare X = X + 1; #end
camera { location -(2*S+10)*z }
// --** end **--
The +3000 term in the seed() is just to keep X*Y positive.
Next I tried a macro:
#declare Col = random(X,Y);
where
#macro random (N1, N2)
#declare IM = 233280;
#declare IA = 1861;
#declare IC = 49297;
#declare LN = mod(N1 * 117127 + N2 * 121499, IM);
#declare LN = mod(LN + IM, IM);
#declare maxC = 8;
#declare C = 0; #while (C < maxC)
#declare LN = mod(LN * IA + IC, IM);
#declare C = C + 1; #end
#declare N3 = LN;
(N3/IM)
#end
which is a 'quick and dirty' LCRG with the inputs multiplied by large
(prime?) numbers. This gave results worse than the first attempt! Highly
correlated adjacent values.
So as a last attempt I put
#declare maxC = 40-floor(30*LN/IM);
and *gasp!* it gave a visually random pattern. I have done no stats on
the output, but it looks similar to a pattern created by putting
#declare Col = rand(R);
into the X, Y loops after initializing R with seed() outside the loops.
So, there you have my investigations into random numbers. I'm sorry if
this post seems as random; I've been typing it intermittently at work
over the last four hours or so ... time to post it I guess.
Bye for now,
Mike Andrews.
// --** active sig alert **--
plane{y,0 pigment{color rgb 1}}camera{location<1,5,-2>look_at 0}
light_source{10 color 1.5}#declare g=sqrt(3);#macro m(a,b,c,n,i)
#if(i=0)cylinder{a,b,c pigment{color rgb vnormalize(<abs(a.x),max
(0,4*(1-abs(a.z))-abs(a.x)),4*abs(a.z)>)}}#else#local f=vlength(a
-b)/32;#local d=(b-a)/8;#local e=vnormalize(vcross(d,n))*f*4;m(a-
e,a+e,f,n,i-1)m(a+d+(1-g)*e,a+2*d+e,f,n,i-1)m(a+6*d+e,a+8*d+e,f,n
,i-1)m(a+e,a+d+(1-g)*e,f,n,i-1)m(a+6*d-e,a+8*d-e,f,n,i-1)m(a+2*d+
e,a+2*d-e,f,n,i-1)m(a+6*d-e,a+6*d+e,f,n,i-1)m(a+3*d-e,a+3*d+e,f,n
,i-1)m(a+4*d-e,a+4*d+e,f,n,i-1)m(a+4*d,a+(4+g)*d+e,f,n,i-1)m(a+6*
d,a+8*d,f,n,i-1)m(a+4*d,a+(4+g)*d-e,f,n,i-1)#end#end
m(-3*x,3*x,1/8,y,3) // Mike Andrews after Jan Walzer
// --** end **--
Post a reply to this message
|
![](/i/fill.gif) |